﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JzSport.WebApp.Promotional
{
    public partial class PromotionalList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void _ctlList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string commandName = e.CommandName;
            if (string.Equals(commandName, "delete", StringComparison.CurrentCultureIgnoreCase))
            {
                string password = _ctlEditPassword.Text.Trim();
                if (string.Equals(password, "jZ13786"))
                {
                    string commandArgument = e.CommandArgument.ToString();
                    Guid promotionalActivityId = Guid.Empty;
                    if (Guid.TryParse(commandArgument, out promotionalActivityId))
                    {
                        if (new DeleteService().DeletePromotionalActivity(promotionalActivityId).ErrorCode == ErrorCode.NoError)
                        {
                            _ctlBtnSearch_Click(null, null);
                            return;
                        }
                    }
                }
                Response.Write("<script>alert('删除失败!');</script>");
            }
        }

        protected void _ctlBtnSearch_Click(object sender, EventArgs e)
        {
            string city = _ctlEditCity.Text.Trim();
            ServiceResult<PagedList<PromotionalActivity>> result = new PromotionalActivityService().GetPagedList(city, 0, 9999);

            _ctlList.DataSource = result.Data.Items;
            _ctlList.DataBind();
        }
    }
}